﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.DataAccess;
using System.Data;
using XMK.Tadong.WebServiceModel.Cond;
using XMK.Utils;

namespace XMK.Tadong.WebServiceData
{
    public class FileData
    {
        private DbProvider dbProvider;
        public FileData(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="cond"></param>
        /// <returns></returns>
        public bool SaveFile(string userId, FileAddCond cond)
        {
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "SP_BatInsertFile", delegate
                {
                    List<IDbDataParameter> pList = DbCmdHelper.CreateParameters(dbProvider, "FILE_NAME", "FILE_EXT", "FILE_ABST", "FILE_AUTHOR", "KEYW", "FILE_CRT_DATE",
                           "FILE_VERSION", "DEST_OBJ", "BIZ_OBJ", "SECRET_LVL", "LANG_TYPE", "FILE_TYPE", "SAVE_PATH", "TEAM_ID", "USER_ID", "FILE_SIZE");
                    return pList.ToArray();
                });
            cmd.SetParamValues(cond.FILE_NAME,cond.FILE_EXT,cond.FILE_ABST,cond.FILE_AUTHOR,cond.KEYW,cond.FILE_CRT_DATE,cond.FILE_VERSION,cond.DEST_OBJ,cond.BIZ_OBJ,cond.SECRET_LVL,cond.LANG_TYPE,cond.FILE_TYPE,cond.SAVE_PATH,cond.TEAM_ID,cond.USER_ID,cond.FILE_SIZE);
            return DbManager.ExecNonQuery(cmd) > 0;
        }

        /// <summary>
        /// 目标树
        /// </summary>
        /// <returns></returns>
        public  List<TreeInfo> QueryTreeInfo(string userId){
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, "SP_BATTARGETTREE");
            List<TreeInfo> treeList = DbManager.GetInfoList<TreeInfo>(cmd,
                delegate(out TreeInfo treeinfo, DataRow row)
                {
                    treeinfo = new TreeInfo
                    {
                        obj_ID = ParseHelper.Parse<int>(row["obj_ID"]),
                        obj_Name = ParseHelper.Parse<string>(row["obj_Name"]),
                        p_obj_ID = ParseHelper.Parse<int>(row["p_obj_ID"])
                    };
                });
            return treeList;
        }
    }
}
